<template>
    <!-- 未绑定则自动弹出抖音扫码弹窗 -->
    <dyPopup v-model="isShowNotBindCode" :isDyBg="true" :showClose="true" @button1Click="saveCodeImage" :contentHeight="520">
        <view class="code-wapper common-wapper">
            <view class="title-text">抖音扫描二维码</view>
            <image :src="codeImage" show-menu-by-longpress class="image" />
            <view class="remind-box">
                <view class="remind-title">授权步骤：</view>
                <view class="flex remind-item col-center">
                    <view class="num-dot">1</view>
                    <text class="text-left">保存二维码至相册</text>
                </view>
                <view class="flex remind-item col-center">
                    <view class="num-dot">2</view>
                    <text class="text-left">打开抖音app，扫描‘相册’里的二维码</text>
                </view>
                <view class="flex remind-item col-center">
                    <view class="num-dot">3</view>
                    <text class="text-left">点击【授权绑定】--【同意】，即完成授权</text>
                </view>
            </view>
        </view>
    </dyPopup>
  </template>
  
  <script>
  import dyPopup from '@/components/dyPopup';
  import { saveCodeImageCom } from '@/utils/common';
  import { mapMutations, mapGetters } from 'vuex';
  import { getDyAuthCode } from '@/utils';
  export default {
      name: 'dyPopupBind',
      components: { dyPopup },
      data(){
          return {
            codeImage: ''
          }
      },
      computed: {
		...mapGetters(['getDyCodeImage', 'getToken','getIsShowNotBindCode']),
        isShowNotBindCode() {
            console.log(this.getIsShowNotBindCode)
            return this.getIsShowNotBindCode || false
        }
      },
      created() {
        const { getDyCodeImage = '' } = this
        if (getDyCodeImage) {
            this.codeImage = getDyCodeImage;
        } else {
            getDyAuthCode().then((res) => {
                console.log(res);
                if (res) {
                    this.codeImage = res;
                } else {
                    uni.showToast({
                        icon: 'none',
                        title: '暂无二维码'
                    });
                }
            });
        }
      },
      methods: {
        ...mapMutations(['changeShowNotBindCode']),
        // 保存二维码
		saveCodeImage() {
			const self = this;
			saveCodeImageCom(this.codeImage, function () {
				self.changeShowNotBindCode(false)
			});
		},
      }
  }
  </script>
  
<style lang="scss">
@import '@/style/common.scss';
</style>